package sifeap.dal.ejb.eventos;

import java.util.List;

import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

import sifeap.dal.ejb.AbstractFacade;
import sifeap.entities.eventos.Evento;
import sifeap.exception.SifeapException;

/**
 * Session Bean implementation class EventoBL
 */
@Stateless(name="EventoDAL")
public class EventoDAL extends AbstractFacade<Evento> implements EventoDALLocal {

	@PersistenceContext(unitName = "sifeapPU")
	private EntityManager em;
	
    /**
     * Default constructor. 
     */
    public EventoDAL() {
    	super(Evento.class);
    }

	@Override
	protected EntityManager getEntityManager() {
		return em;
	}
	
	@Override
	public List<Evento> buscarEventosVigentes() throws SifeapException {
		List<Evento> listaEventos = null;
		try {
			final javax.persistence.Query query = em.createNamedQuery("eventosVigentes", Evento.class);
			query.setHint("javax.persistence.cache.storeMode", "REFRESH");
			listaEventos = query.getResultList();
		} catch (Exception e) {
			throw new SifeapException(e);
		}
		return listaEventos;
	}
}
